/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component,Fragment} from 'react';
import {
  Form,
  Input,
  InputNumber,
  Radio,
  TreeSelect,
  Select,
  DatePicker,
  Button,
  Upload,
  Icon,
  Cascader,
  Modal
} from 'antd';
import {connect} from 'dva';
import {download} from '@/utils/utils';
import request from '@/utils/request';
import config from '@/config/config'
import ReactDataGrid from "react-data-grid";
import BuildModalTitle from "@/components/BuildModalTitle";
import ImportFile2 from './ImportFile2'
const FormItem = Form.Item;
const Option = Select.Option;
class EditUserArchives extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fileList: [],
      concentrators:[],
      all_protocols:[]
    };
  }
  componentDidMount() {
    // this.props.findChildFunc(this.getState);
    const that=this
  }
  getState=()=>{
    return this.state.fileList
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };
    const props = {
      onRemove: (file) => {
        this.setState(({ fileList }) => {
          const index = fileList.indexOf(file);
          const newFileList = fileList.slice();
          newFileList.splice(index, 1);
          return {
            fileList: newFileList,
          };
        });
      },
      beforeUpload: (file) => {
        this.setState(({ fileList }) => ({
          fileList: [file],
        }));
        return false;
      },
      fileList: this.state.fileList,
    };
    const defaultColumnProperties = {
      resizable: true,
    };
    const {getFieldDecorator, getFieldValue} = this.props.form;
    const columns1 = [
      {
        name: '文件名称',
        width: 150,
        key: 'name',
      },
      {
        name: '上传时间',
        width: 170,
        key: 'driver',
      },
      {
        name: '操作',
        width: 160,
        key: 'right',
        classname: 'operate',
        formatter: (event) => <Fragment>
          {
            <Button
              type="primary"
              size="small"
              icon="edit"
              onClick={(e) => {
                this.setState({
                  editRecord: event.row,
                  editModal: true,
                });
              }
              }
            >下载
            </Button>
          }
          {
            <Button
              type="danger"
              icon="delete"
              size="small"
              onClick={()=>{
                this.setState({
                  fileType:event.row.name,
                  importModal:true
                })
              }}
            >删除
            </Button>
          }
        </Fragment>,
      },

    ].map(c => ({ ...defaultColumnProperties, ...c }));
    const file_data =[]

    return (
      <div>
        <Button type={'primary'} block style={{marginBottom:'16px'}} onClick={()=>{
          this.setState({
            importModal:true
          })
        }}>上传文件</Button>
        <ReactDataGrid
          columns={columns1}
          rowGetter={i => {
            return { ...file_data[i], _index: i };
          }}
          rowsCount={file_data.length}
          minHeight={281}

        />
        <Modal
          title={<BuildModalTitle visible={this.state.importModal} modalClass="importModal" title={`上传${this.props.fileType}文件`}/>}
          visible={this.state.importModal}
          centered
          onOk={this.handleImport}
          className="importModal"
          onCancel={() => {
            this.setState({ importModal: false });
          }}

        >
          <ImportFile2 fileType={this.props.fileType} wrappedComponentRef={(inst) => this.importFormRef = inst}/>
        </Modal>
      </div>
    );
  }
}

const EditUserArchivesFormWrap = Form.create()(EditUserArchives);
export default connect()(EditUserArchivesFormWrap);
